package demo1;

public class demo_09InterruptBlock {
    public static void main(String[] args) throws InterruptedException {
        Thread thread =new Thread(()->{
            //此时线程大部分时间是在休眠状态
            while (!Thread.currentThread().isInterrupted()){
                System.out.println("hello thread。。。。。");
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    System.out.println("休眠中被中断");
                    e.printStackTrace();
                    //代码实现逻辑中断，如果想要让他中断即停止我们可以使用break或者return
                    break;
                }
            }
            System.out.println("线程已退出");
        });
        //启动线程
        thread.start();
        //保证线程已经启动
        Thread.sleep(3000);
        //修改中断标志
        thread.interrupt();
    }
}
